home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue58 / Clinic / RichEditCopyingU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-04-19  |  1.5 KB  |  70 lines

  1. unit RichEditCopyingU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     reSrc: TRichEdit;
  12.     reDest: TRichEdit;
  13.     Button1: TButton;
  14.     Label1: TLabel;
  15.     Label2: TLabel;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. uses
  32.   RichOle, RichEdit, ActiveX, ComObj;
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. begin
  36.   reSrc.Lines.LoadFromFile('File.RTF');
  37. end;
  38.  
  39. procedure TForm1.Button1Click(Sender: TObject);
  40. var
  41.   reoSrc, reoDest: IRichEditOle;
  42.   DataObj: IDataObject;
  43.   CharRange: TCharRange;
  44. begin
  45.   //Copies text but not formatting
  46.   //reDest.Lines.Text := reSrc.SelText;
  47.  
  48.   //Copies text and formatting, but uses the clipboard
  49.   //reSrc.CopyToClipboard;
  50.   //reDest.PasteFromClipboard;
  51.  
  52.   //Copies any range, with formatting, and
  53.   //without destroying the clipboard contents
  54.   reSrc.Perform(EM_GETOLEINTERFACE, 0, LParam(@reoSrc));
  55.   if Assigned(reoSrc) then
  56.   begin
  57.     CharRange.cpMin := reSrc.SelStart;
  58.     CharRange.cpMax := reSrc.SelStart + reSrc.SelLength;
  59.     reoSrc.GetClipboardData(CharRange, RECO_COPY, DataObj);
  60.     if Assigned(DataObj) then
  61.     begin
  62.       reDest.Perform(EM_GETOLEINTERFACE, 0, LParam(@reoDest));
  63.       if Assigned(reoDest) then
  64.         reoDest.ImportDataObject(DataObj, 0, 0);
  65.     end
  66.   end
  67. end;
  68.  
  69. end.
  70.